home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-05-19 | 1.7 KB | 95 lines | [TEXT/CWIE] |
- // #include "gltron.h"
- #include <stdio.h>
- #include <stdlib.h>
-
- #ifdef macintosh
- # define SEPERATOR ':'
- #endif
-
- #ifdef WIN32
- # define SEPERATOR '\\'
- #endif
-
- #ifndef SEPERATOR
- # define SEPERATOR '/'
- #endif
-
- static int n_dirs = 2;
-
- #ifdef macintosh
- static char *dirs[] = { ":Data", ":art" };
- #else
- static char *dirs[] = { "data", "art" };
- #endif
-
- /* -dw- methods to tell if a file or folder exists */
- #ifdef macintosh
-
- #include <Files.h>
-
- extern OSStatus GetApplicationDirectory(short *vRefNum, long *dirID); /* in directory.c */
-
- static int itemExists ( const char* path ) {
-
- OSStatus err;
-
- Str255 relPath;
- StringPtr pstr = relPath; /* Str255 is an array, but I want pointer arithmetic */
-
- short vRefNum;
- long dirID;
- FSSpec spec;
-
- int len = strlen(path) + 1;
-
- pstr[0] = len;
-
- if (*path != ':') { /* we only handle relative paths, so make it so */
- pstr[0]++;
- pstr[1] = ':';
- pstr++;
- }
-
- memcpy (pstr + 1, path, len);
- pstr [ len ] = ':';
-
- err = GetApplicationDirectory (&vRefNum, &dirID);
- if (err != noErr) {
- fprintf (stderr, "GetApplicationDirectory failed\n");
- exit (-1);
- }
-
- err = FSMakeFSSpec (vRefNum, dirID, relPath, &spec);
-
- return (err == noErr);
- }
-
- #else
-
- #include <unistd.h>
-
- static int itemExists ( const char* path) {
-
- return access (path, F_OK);
- }
-
- #endif
-
- char* getFullPath(char *filename) {
- char *path;
-
- int i;
- for(i = 0; i < n_dirs; i++) {
- path = malloc(strlen(dirs[i]) + 1 + strlen(filename) + 1);
- sprintf(path, "%s%c%s", dirs[i], SEPERATOR, filename);
- printf("checking '%s'...", path);
- if ( itemExists (path) ) {
- printf("ok\n");
- return path;
- }
- free(path);
- printf("unsuccessful\n");
- }
- return NULL;
- }
-